#******************************************************************************
#******************************************************************************

def PrandtlNumber(specific_heat, dynamic_viscosity, thermal_conductivity):
    """Calculates the Prandtl number for a given fluid."""
    
    return (specific_heat*dynamic_viscosity/thermal_conductivity)

#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************

def ReynoldsNumber(characteristic_length, 
                   fluid_speed,
                   kinematic_viscosity):
    """Calculates the Reynolds number."""
    
    return (fluid_speed*characteristic_length/kinematic_viscosity)
        
#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************

def NusseltNumber(characteristic_length, 
                  heat_transfer_coefficient,
                  thermal_conductivity):
    """Calculates the Nusselt number from a given heat transfer coefficient."""
    
    return (heat_transfer_coefficient*
            characteristic_length/thermal_conductivity)
        
#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************

def MeanFluidSpeedFromReynoldsNumber(characteristic_length,
                                     reynolds_number,
                                     kinematic_viscosity):
    """Calculates the mean fluid speed from the Reynolds number."""
    
    return reynolds_number*kinematic_viscosity/characteristic_length
        
#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************

def ConvectionHeatTransferCoefficient(characteristic_length,
                                      nusselt_number, 
                                      thermal_conductivity):
    """Calculates the heat transfer coefficient for a given Nusselt number."""
    
    return (thermal_conductivity*
            nusselt_number/characteristic_length)
                
#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************

def ThermalDiffusivity(thermal_conductivity,
                       mass_density,
                       specific_heat):
    """Calculates the thermal diffusivity from other fluid properties."""
    
    return (
        thermal_conductivity/(mass_density*specific_heat)
        )
                
#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************

def KinematicViscosity(dynamic_viscosity,
                       mass_density):
    """Calculates the kinematic viscosity from other fluid properties."""
    
    return (
        dynamic_viscosity/mass_density
        )
                
#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************

def HeatTransferRateMassFlow(temperature_in,
                             temperature_out,
                             mass_flow_rate,
                             specific_heat):
    """Calculates the heat transfer by mass flow (positive for hotter output)."""
    
    return (temperature_out-temperature_in)*mass_flow_rate*specific_heat
                
#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************

def HeatTransferRateNewtonLawCooling(temperature_difference,
                                     heat_transfer_coefficient,
                                     surface_area):
    """Calculates the heat transfer rate using Newton\'s law of cooling."""
    
    return temperature_difference*heat_transfer_coefficient*surface_area

#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************

def HeatTransferRateThermalResistance(temperature_difference, 
                                      thermal_resistance):
     """Calculates the heat transfer rate for a given thermal resistance."""
    
     return temperature_difference/thermal_resistance

#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************

def VolumetricFlowRateFromMassFlowRate(mass_flow_rate,
                                       fluid_mass_density):
    """Calculates the volumetric flow rate from the mass flow rate."""
    
    # With SI units:
    # mass flow rate: kg/s
    # volumetric flow rate: m3/s
    # mass_density: kg/m3
    
    return mass_flow_rate/fluid_mass_density

#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************

def MassFlowRateFromVolumetricFlowRate(volumetric_flow_rate,
                                       fluid_mass_density):
    """Calculates the mass flow rate from the volumetric flow rate."""
    
    # With SI units:
    # mass flow rate: kg/s
    # volumetric flow rate: m3/s
    # mass_density: kg/m3
    
    return volumetric_flow_rate*fluid_mass_density

#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************

def MassFlowRateFromHeatFlowRate(heat_flow_rate,
                                 temperature_difference,
                                 specific_heat):
    """Calculates the mass flow rate from the heat flow rate."""

    return heat_flow_rate/specific_heat*temperature_difference

#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************

def MeanFluidSpeedViaVolumetricFlowRate(volumetric_flow_rate,
                                        cross_sectional_area):
    """Calculates the mean fluid speed from the volumetric flow rate."""
    
    # pipe cross-sectional area: pi*(d/2)^2
    # volumetric flow rate = fluid_speed*pi*(d/2)^2
    
    return volumetric_flow_rate/cross_sectional_area

#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************

def VolumetricFlowRateFromMeanFluidSpeed(mean_fluid_speed,
                                         cross_sectional_area):
    """Calculates the volumetric flow rate from the mean fluid speed."""
    
    # pipe cross-sectional area: pi*(d/2)^2
    # volumetric flow rate = fluid_speed*pi*(d/2)^2
    
    return mean_fluid_speed*cross_sectional_area

#******************************************************************************
#******************************************************************************
#******************************************************************************
#******************************************************************************